package com.xyzk.diagnose.activity.adapter;

import java.util.ArrayList;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.TApplication;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MainAdapter extends BaseAdapter{
	private int [] resIds;
	private int resId;

	public MainAdapter(ArrayList<String> datas,int [] resIds, int resId) {
		super(datas);
		this.resIds = resIds;
		this.resId = resId;
	}

	@SuppressWarnings("deprecation")
	@Override
	public View getView(int pos, View view, ViewGroup parent) {
		ViewHolder vh;
		if(view == null){
			view = View.inflate(TApplication.getContext(), resId, null);
			vh = new ViewHolder();
			vh.textview = (TextView) view.findViewById(R.id.tv_mainactivity_item);
			view.setTag(vh);
		}else{
			vh = (ViewHolder) view.getTag();
		}
		Drawable drawable = TApplication.getContext().getResources().getDrawable(resIds[pos]);
		drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
		vh.textview.setCompoundDrawables(null,drawable,null,null);
		vh.textview.setText(getItem(pos));
		return view;
	}

	class ViewHolder{
		TextView textview;
	}
}
